package com.fanyouzhao.ssm251.aop;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * UserDao反射控制器，用于提供给Proxy代理器中的反射执行方法
 * @author: fanyouzhao
 * @date: 9:38 2021/5/27
 */
@Component
public class UserDaoInvocationHandler implements InvocationHandler {

    // 代理对象：声明为UserDao接口类型的对象(自动装配)
    @Resource
    UserDao userDao;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("前置增强");
        // Integer insert = userDao.insert();

        Object invoke = method.invoke(userDao, args);
        System.out.println("后置增强");

        return invoke;
    }
}
